#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QImage>
#include <QFile>
#include <QFileDialog>
#include <QMessageBox>
#include <QByteArray>
#include <QListWidgetItem>
#include <QResizeEvent>

#include "basecore.hpp"
#include "imageshowlabel.h"

QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();

    void Inform(QString strdata);

private slots:
    void resizeEvent(QResizeEvent *event);

    void on_btn_ReadImage_clicked();
    void on_comboBox_showMode_currentIndexChanged(int index);
    void on_btn_outputHex_clicked();
    void on_btn_allImagePath_clicked();
    void on_btn_serarch_clicked();
    void on_btn_allOutputHex_clicked();
    void on_listWidget_imagesName_itemClicked(QListWidgetItem *item);

    void on_horizontalSlider_threshold_valueChanged(int value);

    void on_btn_saveImage_clicked();

    void on_spinBox_outWidth_valueChanged(int arg1);

    void on_spinBox_outHeight_valueChanged(int arg1);

    void on_checkBox_lockWidthHeight_stateChanged(int arg1);

    void on_comboBox_scale_currentIndexChanged(int index);

private:
    ///
    /// \brief 转灰度图像
    /// \param image
    /// \return
    ///
    QImage grayScaleImg(QImage image);
    ///
    /// \brief 灰度图像转为单通道图像
    /// \param image
    /// \return
    ///
    QImage thresholdImg(QImage image);
    ///
    /// \brief 通过路径读取并显示图像
    /// \param 路径
    ///
    void loadImage(QString path);
    ///
    /// \brief 显示图像
    /// \param image
    ///
    void showImage(QImage image);
    ///
    /// \brief 判断路径文件是否存在
    /// \param path
    /// \return
    ///
    bool isFileExist(QString path);
    ///
    /// \brief 图像转为单像素hex数据
    /// \param image
    /// \param datas
    /// \return
    ///
    bool imageToHEX(QImage image, char* datas);
    ///
    /// \brief 获取像素点
    /// \param image
    /// \param col
    /// \param row
    /// \return
    ///
    int getPixel(const QImage image, const int col, const int row);
    ///
    /// \brief 保存数据为bin格式
    /// \param path
    /// \param data
    /// \return
    ///
    bool SaveBin(QString path, QByteArray data);

    ///
    /// \brief 比例转换
    /// \param x2
    /// \param x1
    /// \param y1
    /// \return
    ///
    int ProportionConversion(int x2, int x1, int y1);

    QByteArray AddFileHeader(int num, int bytelength);

    Ui::MainWindow *ui;
    QImage m_image;
    //QImage m_grayImage;
    //QImage m_ThresImage;
    int m_bThres;

    QString m_allimagepath;

    QString lastPath;

    int m_changevalue_;

};
#endif // MAINWINDOW_H
